package cn.itcast.job;



import cn.itcast.domain.system.User;
import cn.itcast.service.company.CompanyService;
import cn.itcast.service.system.UserService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;

@Component("contractJob")
public class ContractJob {
    @Autowired
    private AmqpTemplate amqpTemplate;
   @Reference
    private UserService userService;
    public void contractE(){
       Date date=new Date();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(date);
       calendar.add(Calendar.DAY_OF_MONTH,3);
       Date time = calendar.getTime();
       String newDate = sdf.format(time);
       List<User>userList =userService.findByDate(newDate);
        if(userList!=null&&userList.size()>0) {
            for (User user : userList) {
                Map<String , String> map = new HashMap<>();
                map.put("to" , user.getEmail());
                map.put("subject" , "货物提交提醒");
                map.put("content" , "亲爱的：交货期限要到了哦，抓紧时间提交货物！");
                amqpTemplate.convertAndSend("mail.send" , map);
            }
        }
   }
}
